<template>
	<view class="follow">
		<!-- 导航切换  -->
		<view class="follow-tab">
			<view class="follow-tab__box">
				<view class="follow-tab__item" :class="{ active: activeIndex === 0 }" @click="tab(0)">文章</view>
				<view class="follow-tab__item" :class="{ active: activeIndex === 1 }" @click="tab(1)">作者</view>
			</view>
		</view>
		<view class="follow-list">
			<swiper class="follow-list__swiper" :current="activeIndex" @change="change">
				<swiper-item class="swiper-item">
					<list-scroll>
						<list-item :list="list" :load="load"></list-item>
					</list-scroll>
				</swiper-item>
				<swiper-item class="swiper-item">
					<list-scroll>
						<list-author v-for="item in  authorLists" :key="item.id" :item="item"></list-author>
					</list-scroll>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import listItem from '@/components/list/list-item.vue'
export default {
	components: {
		listItem
	},
	data() {
		return {
			activeIndex: 0,
			list: [],
			load: {
				loading: 'loading'
			},
			authorLists: [],
			followShow: true
		};
	},
	onLoad() {
		this.get_follow()
		this.getAuhtor()
	},
	created() {
		uni.$on('update_article', (e) => {
			this.get_follow()
		})
	},
	methods: {
		get_follow() {
			this.$api.get_follow().then(data => {
				this.list = data
				this.load = {
					loading: 'noMore'
				}
			})
		},
		tab(index) {
			this.activeIndex = index;
		},
		change(e) {
			this.activeIndex = e.detail.current;
		},
		getAuhtor() {
			this.$api.get_author().then(data => {
				this.authorLists = data
				this.followShow = this.authorLists.length === 0 ? true : false
			})
		}
	}
};
</script>

<style lang="scss">
page {
	height: 100%;
	display: flex;
}

.follow {
	// height: 100%;
	display: flex;
	flex-direction: column;
	flex: 1;
	box-sizing: border-box;

	.follow-tab {
		height: 30px;
		padding: 10px 20px;
		border-bottom: 1px #f5f5f5 solid;

		.follow-tab__box {
			display: flex;
			width: 100%;
			height: 100%;
			border-radius: 5px;
			border: 1px $news-color solid;

			.follow-tab__item {
				display: flex;
				justify-content: center;
				align-items: center;
				color: #666;
				font-size: 14px;
				width: 100%;

				&:first-child {
					border-right: 1px $news-color solid;
				}

				&.active {
					color: $news-color;
				}
			}
		}
	}
	.follow-list {
		flex: 1;

		.follow-list__swiper {
			height: 100%;

			.swiper-item {
				height: 100%;
			}
		}
	}
}

.no-data {
	padding: 50px;
	font-size: 14px;
	color: #999;
	text-align: center;
}
</style>
